import 'package:dio/dio.dart';
import 'dart:io';
import 'dart:async';
import '../utils/api_list.dart';

// Future getHomePageContent() async {
//   print('开始请求接口...');
//   Response response;
//   Dio dio = new Dio();
//   dio.options.headers = {
//     'Content-Type': ContentType.parse('application/x-www-form-urlencoded')
//   };
//   const params = {'lon': '115.02932', 'lat': '35.76189'};
//   response =
//       await dio.post(ApiList['homePageContent'], queryParameters: params);

//   if (response.statusCode == 200) {
//     return response.data;
//   } else {
//     return print('后台数据请求失败~');
//   }
// }

Future request(String url, {params}) async {
  print('开始请求接口...');
  Response response;
  Dio dio = new Dio();
  dio.options.headers = {
    'Content-Type': ContentType.parse('application/x-www-form-urlencoded')
  };

  if (params == null) {
    response = await dio.post(ApiList[url]);
  } else {
    response = await dio.post(ApiList[url], queryParameters: params);
  }

  if (response.statusCode == 200) {
    return response.data;
  } else {
    return print('后台数据请求失败~');
  }
}
